<template>
  <section>
    <div class="model myfile">
      <img :src="IMGBASE64.WODEWENJIAN2X" class="pink">
      <span class="title">学科管理</span>
      <div class="kong"></div>
      <div class="t_title">
        <img>
        <span class="f-blue">学科列表</span>
        <div class="graph">
          <ul>
            <li v-for="item in list">{{item.subjectName}}</li>
          </ul>
        </div>
      </div>
    </div>
    


    <div class="dright">
      <div class="row">
        <span class="headerspan">切换学校:</span>
        <el-select v-model="schoolSelect" @change='getListData' size="small">
          <el-option v-for="item in schoolOption" :label="item.schoolName" :value="item.id"></el-option>
        </el-select>
      </div>

      <!-- <div class="n_btn">
        <img>
        <p>新增</p>
      </div> -->
      <div class="kong"></div>
      <div class="t_title">
        <img>
        <span class="f-blue">学科列表-学科选择</span>
      </div>

      <div class="tree">
        <el-tree
          show-checkbox
          ref="tree"
          :data="data2"
          :props="defaultProps"
          accordion
          node-key="id"
          :default-expanded-keys="[100]">
        </el-tree>
        <div class="bottom">
          <button class="btn btn-danger" @click="tipshow" :disabled='notSbu'>确认提交</button>
        </div>
      </div>
    </div>

    <div class="tipUp" v-show="tipShow">
      <div class="row">
        <span class="err">如若提交,不可更改</span>
      </div>
      <div class="row">
        <el-button type="danger" @click="getCheckedNodes">确定</el-button>
        <el-button @click="tipshow">取消</el-button>
      </div>
    </div>

    <div class="up" v-show="upShow">
      <img :src="IMGBASE64.GREENXINZENG2X" class="green">
      <span class="title">新建</span>
      <el-button icon="el-iocn-close" class="close" @click="upshow()"></el-button>
      <header>
        <span class="header-title">基本信息</span>
      </header>
      <div class="form">
        <div class="firstLine">
          <span>部门名称:</span>
          <input type="text" class="form-longText">
        </div>
        <div class="secondLine">
          <span>创建角色:</span>
          <ul>
            <li><span>角色1</span><input type="text" class="form-text"></li>
            <li><span>角色2</span><input type="text" class="form-text"></li>
            <li><span>角色3</span><input type="text" class="form-text"></li>
          </ul>
        </div>
      </div>
      <div class="bottom">
        <div class="right">
          <el-button type="success">确定</el-button>
        </div>
      </div>
    </div>

    <transition name="modal-shadow">
      <div class="modal-backdrop" v-show="anShow"></div>
    </transition>
  </section>
</template>

<script>
// let code = 1000
export default {
  data () {
    return {
      list: [],
      tipShow: false,
      notSbu: false,
      expand: [100],
      upShow: false,
      anShow: false,
      schoolSelect: null,
      schoolOption: [],
      data2: [],
      chooseArray: [],
      defaultProps: {
        children: 'children',
        label: 'label'
      }
    }
  },
  mounted () {
    this.getSchoolData()
  },
  methods: {
    mover (ev) {
      ev.path[2].lastElementChild.style.opacity = 0
    },
    mout (ev) {
      ev.path[2].lastElementChild.style.opacity = 1
      // console.log(ev)
    },
    append (store, data) {
      // store.append({ code: code++, label: 'testtest', children: [] }, data)
      this.upShow = true
    },
    tipshow () {
      this.tipShow = !this.tipShow
      this.anShow = !this.anShow
    },
    change (store, data) {
      // store.append({ code: code++, label: 'testtest', children: [] }, data)
      this.upShow = true
    },
    getSchoolData () {
      this.$http.post(this._httpUrl + 'sys/school/manage/schoolList', {}, {'headers': {'yxt-xtoken': localStorage.xtoken}}).then(function (response) {
        if (response.body.code === '000') {
          this.schoolOption = response.data.data
        } else if (response.body.code === '887') {
          this.$router.push('/')
        } else if (response.body.code === '889') {
          this.$router.push('/')
        }
      })
    },
    getListData () {
      this.notSbu = false
      console.log('haha' + this.list)
      this.$http.post(this._httpUrl + 'sys/subject/query', {schoolId: this.schoolSelect}, {'headers': {'yxt-xtoken': localStorage.xtoken}}).then(function (response) {
        if (response.body.code === '000') {
          this.list = response.data.data.schoolList
          if (this.list.length !== 0) {
            this.notSbu = true
            console.log(this.notSbu)
            console.log(this.list)
          }
          if (response.data.data.sysList.length !== 0) {
            this.data2 = response.data.data.sysList
            for (var i = 0; i < response.data.data.sysList.length; i++) {
              this.data2[i].id = response.data.data.sysList[i].id
              this.data2[i].label = response.data.data.sysList[i].subjectName
            }
          }
        } else if (response.body.code === '887') {
          this.$router.push('/')
        } else if (response.body.code === '889') {
          this.$router.push('/')
        }
      })
    },
    getCheckedNodes () {
      this.chooseArray = this.$refs.tree.getCheckedNodes()
      for (var i = 0; i < this.chooseArray.length; i++) {
        delete (this.chooseArray[i].label)
        this.chooseArray[i].subjectId = this.chooseArray[i].id
        delete (this.chooseArray[i].id)
      }
      this.getLeftData()
      this.tipShow = !this.tipShow
      this.anShow = !this.anShow
      this.notSbu = true
    },
    getLeftData () {
      this.$http.post(this._httpUrl + 'sys/subject/initCreate', {schoolId: this.schoolSelect, schoolList: this.chooseArray}, {'headers': {'yxt-xtoken': localStorage.xtoken}}).then(function (response) {
        if (response.body.code === '000') {
          this.$http.post(this._httpUrl + 'sys/subject/query', {schoolId: this.schoolSelect}, {'headers': {'yxt-xtoken': localStorage.xtoken}}).then(function (response) {
            if (response.body.code === '000') {
              this.list = response.data.data.schoolList
              // if (response.data.data.sysList.length !== 0) {
              //   this.data2 = response.data.data.sysList
              //   for (var i = 0; i < response.data.data.sysList.length; i++) {
              //     this.data2[i].id = response.data.data.sysList[i].id
              //     this.data2[i].label = response.data.data.sysList[i].subjectName
              //   }
              // }
            } else if (response.body.code === '887') {
              this.$router.push('/')
            } else if (response.body.code === '889') {
              this.$router.push('/')
            }
          })
        }
      })
    },
    remove (store, data) {
      store.remove(data)
    },
    upshow () {
      this.upShow = !this.upShow
      this.anShow = !this.anShow
    }
  }
}
</script>

<style scoped>
@import '/static/css/material-dashboard.css';
  .myfile{
    width:54% !important;
    min-width: 595.67px !important;
    height: 440px;
  }
  .myfile .el-tree{
    position: relative; left: 42%;
    width: 210.4%;
    border: none;
  }
  .myfile .t_title{
    position: relative; left: 18%;
  }
  .myfile .t_title img{
    float: left;
    width: 20px; height: 20px;
    background: #ccc;
    margin-right: 1%;
  }
  section .line{
    position: absolute; left: 55%; top: 60px;
    width: 1px; height: 56%;
    border-left: 1px dashed #666;
  }
  section .dright{
    position: absolute; right: 2%; top: 51px;
    width: 40%; height: 460px;
    background: #fff;
    border-radius: 4px;
  }
  section .dright .row{
    margin-top: 20px;
  }
  section .dright .n_btn{
    position: absolute; right: 2.4%; top: 16px;
    width: 14%;
  }
  section .dright .n_btn img{
    width: 20px; height: 20px;
    background: #ccc;
    float: left;
  }
  section .dright .n_btn p{
    position: relative; left: 4%;
    font-size: 14px;
  }
  section .dright .t_title{
    margin-left: 6%;
  }
  .graph{
    height: 290px;
    overflow-y: scroll;
  }
  .graph ul{
    overflow: hidden;
  }
  .graph ul li{
    float: left;
    height: 24px; line-height: 24px;
    width: 16%;
    margin-top: 34px;
    margin-right: 10%;
    background: #c4e7f7;
    border-radius: 24px;
    text-align: center;
    font-size: 14px;
  }
  section .dright .t_title img{
    float: left;
    width: 20px; height: 20px;
    background: #ccc;
    margin-right: 1%;
  }
  section .dright .headerspan{
    position: relative;
    margin-left: 6%;
  }
  section .dright select{
    position: relative; top: 12px;
    width: 54%;
    border: none;
    border-bottom: 1px solid #ccc;
  }
  section .dright .t-btn{
    position: relative; left: 34%; top: 14px;
  }
  section .dright .tree{
    position: relative; left: 6%; top: 10px;
    width: 90%;
  }
  section .tree{
    position: relative; left: 2%; top: 14px;
  }
  section .tree .bottom{
    text-align: center;
  }
  div[data-v-22bf8d34] ul
  {
    position: relative;
    left: 12%;
  }
  div[data-v-22bf8d34]
  {
    padding-bottom: 10px;
  }
  .el-upload--picture-card
  {
    margin-left: 9%; 
    margin-top: 40px;
    width: 80px; height: 80px;
  }
  .el-upload--picture-card i
  {
    position: relative; top: -28px;
  }
  .tree{
    position: relative; left: 60%;
    width: 40%;
  }
  .span{
    opacity: 0;
  }

  .up{
    width: 60%;
    position: absolute;
    top: 10%;
    left: 25%;
    background: #FFF;
    padding: 20px 20px 0 20px;
    border-radius: 5px;
    z-index: 99999;
  }
  .up .img{
    position: absolute;
    left: 24px;
    top: -20px;
  }
  .up .title{
    margin-left: 90px;
  }
  .up header{
    border-bottom: 2px solid #D7D7D7;
    padding: 30px 0 10px 0;
    margin-left: 1%;
    margin-right: 10px;
    margin-bottom: 10px;
  }
  .up .header-title{
    color: #FB7862;
    border-bottom: 2px solid #FB7862;
    padding: 0 10px 10px 10px;
    margin-left: 0;
  }
  .up .form{
    margin-left: 10%;
    margin-right: 10px;
  }
  .up .form .firstLine{
    padding: 30px 0 10px 0;
  }
  .up .form .secondLine{
    padding: 30px 0 50px 0;
  }
  .up .form .form-longText{
    width: 50%;
    border: 0;
    border-bottom: 1px solid #D7D7D7;
  }
  .up .form .form-text{
    width: 70%;
    border: 0;
    border-bottom: 1px solid #D7D7D7;
  }
  .up ul{
    margin-top: 30px;
    margin-left: 75px;
  }
  .up ul li{
    float: left;
  }
  .up .bottom{
    border-top: 1px solid #D7D7D7;
    margin-top: 20px;
    background: #F8F8F8;
    padding: 8px 0;
    margin-left: -20px;
    margin-right: -20px;
    border-radius: 0 0 5px 5px;
  }
  .up .bottom .right{
    text-align: right;
    padding: 0 10px 0 0;
  }
  .tipUp{
    width: 30%;
    position: fixed;
    top: 150px;
    left: 50%;
    margin-left: -15%;
    z-index: 99999;
    background: #FFF;
    padding: 20px 20px 20px 20px;
    border-radius: 5px;
  }
  .tipUp .row{
    text-align: center;
    padding-top: 15px;
  }
  .err{
    color: #FA5555;
    font-size: 16px;
  }
</style>
